<template>
  <el-form label-position="left" label-width="80px" :model="form" class="event-editer">
    <el-form-item label="名称">
      <el-input v-model="form.description"></el-input>
    </el-form-item>
    <el-form-item label="分数">
      <el-input-number v-model.number="form.score" controls-position="right" :min="-99" :max="99"></el-input-number>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleSubmit">立即创建</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import api from "@/api";

export default {
  data() {
    return {
      form: {
        description: "",
        score: null
      }
    };
  },
  methods: {
    async handleSubmit() {
      try {
        const { data } = await api.addEvent(this.form);
        this.$emit("success");
        this.$message.success("添加成功");
      } catch (error) {
        this.$message.success("添加失败");
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.event-editer {
  box-sizing: border-box;
  max-width: 600px;
  padding: 8px;
  margin: 0 auto;
}
</style>
